import * as api from "./api";

export default {
    data(){
        let _this = this;
        return{
            // 页面数据
            tableData:[],
            // 当前页
            elPage:1,
            pageSize:3,
            provinceOptions:{
                lazy: true,
                lazyLoad (node, resolve) {
                    const { level } = node;
                    if(level===0){
                        _this.axios({
                            url:api.GET_SELECT_ALLPROCINCE,
                            method:'get',
                            params:{}
                        }).then(data =>{
                            let province = data.data.data;
                            const nodes = province
                                .map(item => ({
                                    value: item.province_id,
                                    label: item.province_name,
                                    leaf: level >= 2
                                }));
                            resolve(nodes);
                        });
                    }else if(level===1){
                        _this.axios({
                            url:api.GET_SELECT_ALLCITY,
                            method:'get',
                            params:{
                                provinceId:node.value
                            }
                        }).then(data =>{
                            let city = data.data.data;
                            const nodes = city
                                .map(item => ({
                                    value: item.city_id,
                                    label: item.city_name,
                                    leaf: level >= 2
                                }));
                            resolve(nodes);
                        });
                    }else if(level===2){
                        _this.axios({
                            url:api.GET_SELECT_ALLAREA,
                            method:'get',
                            params:{
                                cityId:node.value
                            }
                        }).then(data =>{
                            let qu = data.data.data;
                            if(data.data.code===200){
                                const nodes = qu
                                    .map(item => ({
                                        value: item.area_city_id,
                                        label: item.area_name,
                                        leaf: level >= 2
                                    }));
                                resolve(nodes);
                            }else if(data.data.code===500){
                                resolve();
                            }
                        });
                    }
                }
            },
        }
    },
    computed:{
        dangqianyeTableData(){
            let kaishi = (this.elPage - 1) * this.pageSize;
            return this.tableData.slice(kaishi, kaishi+this.pageSize)
        },
    }
    ,
    methods:{
        getFoodTableData(obj){
            this.elPage = 1;
            this.axios({
                method:'get',
                params:obj.data,
                url:obj.url
            }) .then(data =>{
                this.tableData=data.data.data;
                // console.log(this.tableData)
            })
        },
        elChangePage(val) {
            // console.log('当前页是第'+ val +'页');
            this.elPage = val
        },
    }
}